package com.wica.model;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import android.os.Parcel;
import android.os.Parcelable;

public class MovieClip implements Parcelable{

	private String description;
	private Integer duration;
	private String format1;
	private String format5;
	private String format6 ;
	private String title;
	private Float totalrating;
	private String URLThumbnail;
	private String url;
	private Integer viewcount;
	private String category;
	private Float roundRating;
	
	private HashMap<String, String> contentSrc;
	private String latLong;
	private Float latitude;
	private double latitudeE6;
	private Float longitude;
	private double longitudeE6;
	private String tags;
    
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(this.description);
        out.writeInt(this.duration);
        out.writeString(this.format1);
        out.writeString(this.format5);
        out.writeString(this.format6);
        out.writeString(this.title);
        out.writeFloat(this.totalrating);
        out.writeString(this.URLThumbnail);
        out.writeString(this.url);
        out.writeInt(this.viewcount);
        out.writeString(this.category);
        out.writeFloat(this.roundRating);

        /// To "serialize" the HashMap
        out.writeInt(contentSrc.size());
        Iterator i = contentSrc.entrySet().iterator();
        while (i.hasNext()){
            Map.Entry<String, String> e = (Map.Entry<String, String>) i.next();
            out.writeString(e.getKey());
            out.writeString(e.getValue());
        }    }

    public static final Parcelable.Creator CREATOR
            = new Parcelable.Creator() {
        public MovieClip createFromParcel(Parcel in) {
            return new MovieClip(in);
        }

        public MovieClip[] newArray(int size) {
            return new MovieClip[size];
        }
    };
    
    private MovieClip(Parcel in) {
    	this.description = in.readString();
    	this.duration = in.readInt();
		this.format1=in.readString();
		this.format5=in.readString();
		this.format6=in.readString();
		this.title=in.readString();
		this.totalrating=in.readFloat();
		this.URLThumbnail=in.readString();
		this.url=in.readString();
		this.viewcount=in.readInt();
		this.category=in.readString();
		this.roundRating=in.readFloat();	
        
        /// To "deserialize" the HashMap
        int hashSize = in.readInt();
        contentSrc = new HashMap<String, String>();
        for (int i = 0; i < hashSize; i++)
            contentSrc.put(in.readString(), in.readString());        
    }

	
	public MovieClip(String description,Integer duration,String format1,String format5,String format6,String title,Float totalrating,String URLThumbnail,String url,Integer viewcount,String category,Float roundRating,String tags){
		this.description=description;
		this.duration=duration;
		this.format1=format1;
		this.format5=format5;
		this.format6=format6;
		this.title=title;
		this.totalrating=totalrating;
		this.URLThumbnail=URLThumbnail;
		this.url=url;
		this.viewcount=viewcount;
		this.category=category;
		this.roundRating=roundRating;
		this.tags=tags;
	}//MovieClip creation method
	
	public MovieClip(String description,Integer duration,String format1,String format5,String format6,String title,Float totalrating,String URLThumbnail,String url,Integer viewcount,String category,Float roundRating, String latLong,String tags){
		this.description=description;
		this.duration=duration;
		this.format1=format1;
		this.format5=format5;
		this.format6=format6;
		this.title=title;
		this.totalrating=totalrating;
		this.URLThumbnail=URLThumbnail;
		this.url=url;
		this.viewcount=viewcount;
		this.category=category;
		this.roundRating=roundRating;	
		this.latLong=latLong;		
		String[] var = latLong.split(",");
		this.latitude=new Float(var[0]);
		this.latitudeE6=this.latitude*1E6;
		this.longitude=new Float(var[1]);
		this.longitudeE6=this.longitude*1E6;
		this.tags=tags;
	}//MovieClip creation method
	
	// Get methods
	public String getDescription(){
		return description;
	}
	public Integer getDuration(){
		return duration;
	}
	public String getFormat1(){
		return format1;
	}
	public String getFormat5(){
		return format5;
	}
	public String getFormat6(){
		return format6;
	}
	public String getTitle(){
		return title;
	}
	public Float getTotalRating(){
		return totalrating;
	}
	public String getURLThumbnail(){
		return URLThumbnail;
	}
	public String getUrl(){
		return url;
	}
	public Integer getViewcount(){
		return viewcount;
	}
	public String getCategory(){
		return category;
	}
	public Float getRoundRating(){
		return roundRating;
	}	
	public int getLatitudeE6() {
		return (int) latitudeE6;
	}
	public Float getLatitude() {
		return latitude;
	}	
	public int getLongitudeE6() {
		return (int) longitudeE6;
	}
	public Float getLongitude() {
		return longitude;
	}	
	// Set methods
	@Override
	public int describeContents() {
		return 0;
	}


	public String getTags() {
		// TODO Auto-generated method stub
		return this.tags;
	}
}